import { IFeidaoAiBrowserComponent } from '@feidao/web/interfaces';
import show from '@feidao/web/atom/browser/ui/show';
import hide from '@feidao/web/atom/browser/ui/hide';
import get from '@feidao/web/atom/core/local/get';
import { send_msg as url } from './config'

import P004 from './P004';
import P005 from './P005';
import nodejs from '@feidao/web/atom/browser/msg/nodejs';
import render from '@feidao/web/atom/browser/render/render';

export default async function (fd: IFeidaoAiBrowserComponent, ...args: any[]) {

	//绑定微信
	const phone_dom = fd.data.node.querySelector<HTMLDivElement>('[data-feidao="phone"]');
	const wx_dom = fd.data.node.querySelector<HTMLDivElement>('[data-feidao="wx"]');

	const npn_dom = fd.data.node.querySelector<HTMLInputElement>('[data-feidao-id="npn"]');
	const verificationcode_dom = fd.data.node.querySelector<HTMLInputElement>('[data-feidao-id="verificationcode"]');

	npn_dom.value = '';
	verificationcode_dom.value = '';

	const usercode = get(fd, 'usercode');
	const productid = get(fd, 'productid');

	const res = await nodejs(url, 'wx_find', { usercode, productid }, false, false) as Array<{ lengt: string }>

	if (res.length == 0) {
		render(fd, {}, P005, 'P004', 'inner');

	} else {
		render(fd, {}, P004, 'P004', 'inner');
	}

	hide(phone_dom);
	show(wx_dom);
	const node = args[0].target as HTMLElement
	node.classList.add('bg-e')
	node.classList.add('color-ff')
	const node1 = args[0].target.previousElementSibling as HTMLElement
	node1.classList.remove('bg-e')
	node1.classList.remove('color-ff')
}

